package net.mingsoft.config;

import org.springframework.boot.context.properties.*;
import org.springframework.stereotype.*;
import net.mingsoft.base.*;
import cn.hutool.core.util.*;
import org.springframework.core.io.*;

@ConfigurationProperties(prefix = "ms")
@Component
public class MSProperties
{
    public static UploadProperties upload;
    public static ManagerProperties manager;
    public static PeopleProperties people;
    public static DiyProperties diy;
    public static String shiroKey;
    public static String cookieName;
    
    MSProperties() {
        System.out.println("___  ____             _____        __ _    ___  ___ _____ ");
    }
    
    public String getShiroKey() {
        return MSProperties.shiroKey;
    }
    
    public void setShiroKey(final String shiroKey) {
        MSProperties.shiroKey = shiroKey;
    }
    
    public String getCookieName() {
        return MSProperties.cookieName;
    }
    
    public void setCookieName(final String cookieName) {
        MSProperties.cookieName = cookieName;
    }
    
    public ManagerProperties getManager() {
        return MSProperties.manager;
    }
    
    public void setManager(final ManagerProperties manager) {
        MSProperties.manager = manager;
    }
    
    public UploadProperties getUpload() {
        return MSProperties.upload;
    }
    
    public void setUpload(final UploadProperties upload) {
        MSProperties.upload = upload;
    }
    
    public PeopleProperties getPeople() {
        return MSProperties.people;
    }
    
    public static void setPeople(final PeopleProperties people) {
        MSProperties.people = people;
    }
    
    public static DiyProperties getDiy() {
        return MSProperties.diy;
    }
    
    public static void setDiy(final DiyProperties diy) {
        MSProperties.diy = diy;
    }
    
    static {
        MSProperties.upload = new UploadProperties();
        MSProperties.manager = new ManagerProperties();
        MSProperties.people = new PeopleProperties();
        MSProperties.diy = new DiyProperties();
        MSProperties.shiroKey = RandomUtil.randomString(16);
        MSProperties.cookieName = "SHIRO_SESSION_ID";
    }
    
    public static class UploadProperties
    {
        public boolean enableWeb;
        public String template;
        public String path;
        public String mapping;
        public String denied;
        public String backUp;
        public MultipartProperties multipart;
        
        public UploadProperties() {
            this.enableWeb = true;
            this.template = "template";
            this.path = "upload";
            this.mapping = "/upload/**";
            this.denied = ".exe,.jsp";
            this.backUp = "/upload_back";
            this.multipart = new MultipartProperties();
        }
        
        public boolean isEnableWeb() {
            return this.enableWeb;
        }
        
        public void setEnableWeb(final boolean enableWeb) {
            this.enableWeb = enableWeb;
        }
        
        public String getTemplate() {
            return this.template;
        }
        
        public void setTemplate(final String template) {
            this.template = template;
        }
        
        public String getPath() {
            return this.path;
        }
        
        public void setPath(final String path) {
            this.path = path;
        }
        
        public String getMapping() {
            return this.mapping;
        }
        
        public void setMapping(final String mapping) {
            this.mapping = mapping;
        }
        
        public String getDenied() {
            return this.denied;
        }
        
        public void setDenied(final String denied) {
            this.denied = denied;
        }
        
        public String getBackUp() {
            return this.backUp;
        }
        
        public void setBackUp(final String backUp) {
            this.backUp = backUp;
        }
        
        public void denied() {
        }
    }
    
    public static class MultipartProperties
    {
        public long maxFileSize;
        public long maxRequestSize;
        public boolean resolveLazily;
        public String defaultEncoding;
        public Resource uploadTempDir;
        public int maxInMemorySize;
        
        public MultipartProperties() {
            this.maxFileSize = 1024L;
            this.maxRequestSize = 10240L;
            this.resolveLazily = false;
            this.defaultEncoding = "ISO-8859-1";
            this.uploadTempDir = null;
            this.maxInMemorySize = 4096;
        }
        
        public long getMaxFileSize() {
            return this.maxFileSize;
        }
        
        public void setMaxFileSize(final long maxFileSize) {
            this.maxFileSize = maxFileSize;
        }
        
        public long getMaxRequestSize() {
            return this.maxRequestSize;
        }
        
        public void setMaxRequestSize(final long maxRequestSize) {
            this.maxRequestSize = maxRequestSize;
        }
        
        public boolean isResolveLazily() {
            return this.resolveLazily;
        }
        
        public void setResolveLazily(final boolean resolveLazily) {
            this.resolveLazily = resolveLazily;
        }
        
        public String getDefaultEncoding() {
            return this.defaultEncoding;
        }
        
        public void setDefaultEncoding(final String defaultEncoding) {
            this.defaultEncoding = defaultEncoding;
        }
        
        public Resource getUploadTempDir() {
            return this.uploadTempDir;
        }
        
        public void setUploadTempDir(final Resource uploadTempDir) {
            this.uploadTempDir = uploadTempDir;
        }
        
        public int getMaxInMemorySize() {
            return this.maxInMemorySize;
        }
        
        public void setMaxInMemorySize(final int maxInMemorySize) {
            this.maxInMemorySize = maxInMemorySize;
        }
    }
    
    public static class ManagerProperties
    {
        public String path;
        public String viewPath;
        public boolean checkCode;
        public String loginPath;
        
        public ManagerProperties() {
            this.path = "/ms";
            this.viewPath = "/WEB-INF/manager";
            this.checkCode = true;
            this.loginPath = "/login.do";
        }
        
        public String getPath() {
            return this.path;
        }
        
        public void setPath(final String path) {
            this.path = path;
        }
        
        public String getViewPath() {
            return this.viewPath;
        }
        
        public void setViewPath(final String viewPath) {
            this.viewPath = viewPath;
        }
        
        public boolean isCheckCode() {
            return this.checkCode;
        }
        
        public void setCheckCode(final boolean checkCode) {
            this.checkCode = checkCode;
        }
        
        public String getLoginPath() {
            return this.loginPath;
        }
        
        public void setLoginPath(final String loginPath) {
            this.loginPath = loginPath;
        }
    }
    
    public static class PeopleProperties
    {
        public String loginUrl;
        
        public PeopleProperties() {
            this.loginUrl = "/mdiyPage/pc/login.do";
        }
        
        public String getLoginUrl() {
            return this.loginUrl;
        }
        
        public void setLoginUrl(final String loginUrl) {
            this.loginUrl = loginUrl;
        }
    }
    
    public static class DiyProperties
    {
        public String htmlDir;
        
        public DiyProperties() {
            this.htmlDir = "html";
        }
        
        public String getHtmlDir() {
            return this.htmlDir;
        }
        
        public void setHtmlDir(final String htmlDir) {
            this.htmlDir = htmlDir;
        }
    }
}
